package thread;



public class Demo17 {
    private static boolean isQuit = false;

    public static void main(String[] args) throws InterruptedException {
    Thread t = new Thread(()->{
        while(!isQuit) {
            System.out.println("hello,Thread");

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        System.out.println("线程执行结束");
    });

    t.start();
    Thread.sleep(2000);
    System.out.println("main 线程尝试终止 t 线程");
    isQuit = true;


}
}
